<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <title>内置对象</title>
  </head>
  
  <body>
    <%
    	//9大内置对象
    	//1、HttpServletRequest request
    	request.setAttribute("name", "request's message!");	//requestScope
    	out.println(request.getAttribute("name"));
    	//2、HttpServletResponse response
    	response.getWriter().write("response's message!");
    	//3、HttpSession session
    	session.setAttribute("name","session's message!");	//sessionScope
    	out.println("session's id:"+session.getId());
    	//4、ServletConfig config
    	String contextPath=config.getServletContext().getContextPath();
    	out.println("get contextPath from config Object:"+contextPath);
    	//5、ServletContext application
    	application.setAttribute("name","application(context)'s message!");	//applicationScope
    	//6、Throwable exception
    	//the exception Object can use when the isErrorPage is openning
    	//7、Object(this) page
    	//8、JspWriter out
    	out.println("The JspWriter is much more buffer than PeintWriter!");
    	//9、PageContext pageContext		
    	pageContext.setAttribute("name","pageContext's message!");	//pageScope
    %>
    <%
    	//System.out.println("session和request获取的session是否相同："+(session==request.getSession()));
    	//System.out.println("application和request获取的ServletContext是否相同："+(application==request.getServletContext()));
    %>
    <%
    	/* //分别从四个域中拿到指定数据，按照域范围的从大到小
    	//1、pageScope 只在本页面中起作用
    	System.out.println(pageContext.getAttribute("name"));
    	//2、requestScope 只有在转发后的页面起作用，转发后的页面与本页面是同一个request，也就是说，可以在request相同的页面起作用
    	System.out.println(request.getAttribute("name"));
    	//3、SessionScope 在同一个Session路径下（Cookie路径）的所有页面，当Session的持续时间内都可以使用
    	System.out.println(session.getAttribute("name"));
    	//4、application(context) 在整个项目内使用，只有当项目关闭的时候，才会消失
    	System.out.println(application.getAttribute("name"));
    	//请求转发过去到2
    	//request.getRequestDispatcher("/demo05_pageContext2.jsp").forward(request,response);
    	//发送重定向
    	//response.sendRedirect("demo05_pageContext2.jsp");
    	 */
    %>
    <%-- //使用pageContext在域中进行存取数据，原则是在什么域中存的数据，需要在什么域中去取 --%>
    <%-- PAGE_SCOPE --%>
    <%
    	//设置不同域中的数据
    	pageContext.setAttribute("value","page's message!",pageContext.PAGE_SCOPE);
    	pageContext.setAttribute("value","request's message!",pageContext.REQUEST_SCOPE);
    	pageContext.setAttribute("value","session's message!",pageContext.SESSION_SCOPE);
    	pageContext.setAttribute("value","application's message!",pageContext.APPLICATION_SCOPE);
    %>
    <br/>
    <%=pageContext.getAttribute("value",pageContext.PAGE_SCOPE) %>    <br/>
    <%=pageContext.getAttribute("value",pageContext.REQUEST_SCOPE) %>    <br/>
    <%=pageContext.getAttribute("value",pageContext.SESSION_SCOPE) %>    <br/>
    <%=pageContext.getAttribute("value",pageContext.APPLICATION_SCOPE) %>    <br/>
  </body>
</html>
